var tcbj = $('.tc-bj'),
  xhcss = { 
    navs: function (options) {
      options = $.extend({
        navs: '#navs', //nav层
        mclick: '#m-click', //点击层
        add: 'm-click-this' //添加的css
      }, options);
      var navs = $(options.navs),
        clicks = $(options.mclick),
        add = options.add,
        hide = function () {
          clicks.removeClass(add);
          navs.removeClass(add);
          tcbj.hide();
        },
        show = function () {
          clicks.addClass(add);
          navs.addClass(add);
          tcbj.show();
        },
        close = function () {
          if (!tcbj.length > 0) { //判  断背景层是否存在
            //var bj = $("<div class='tc-bj'>sss</div>").appendTo("body");
            $("<div class='tc-bj'></div>")
              .css({ position: 'fixed', top: 0, left: 0, right: 0, bottom: 0, backgroundColor: "#000000", opacity: 0.7, zIndex: 500 })
              .hide().appendTo("body");
            tcbj = $('.tc-bj');
          };
          tcbj.on('click', function () {
            hide();
          })
        };
      clicks.on('click', function () {
        var b = navs.hasClass(add); //判断是否是执行状态
        console.log(b)
        close(); //先执行背景层判断是否存在
        if (b) {
          hide()
        } else {
          show()
        }

      })
    },
    dnnav: function () {
      $submenu = $(".nav-sub");
      $head = $(".header");
      var timer = null;
      $(".nav li").each(function (index) {
        $(this).mouseenter(function () {
          var index = $(this).attr("data-index");
          if (index == 8 || index == 4 || index == 3) {
            $submenu.find(".nav-sub-item" + index).show(0).siblings(".nav-sub-item").hide(0);
            var height = $submenu.find(".nav-sub-item" + index).outerHeight();
            $submenu.height(height);
            $bj.stop(true, false).fadeIn(300);
          } else {
            $submenu.height(0);
            $bj.stop(true, false).fadeOut(300);
            return;
          }
        });
      });

      function hidebj() {
        $submenu.height(0);
        $bj.stop(true, false).fadeOut(300);
      }
      $head.mouseleave(function () {
        timer = setTimeout(function () {
          hidebj();
        }, 200);
      }).mouseenter(function () {
        if (timer) clearTimeout(timer);
      });
      $submenu.mouseleave(function () {
        timer = setTimeout(function () {
          hidebj();
        }, 200);
      }).mouseenter(function () {
        if (timer) clearTimeout(timer);
      });
    }

  }
xhcss.navs();

$('.tc-click').click(function(){
  console.log('2')
  layer.open({
    type: 1
    ,title:'预约'
    ,style:'width:90vw'
    ,content: $('.tc-zt').html()
  });
})
    //人才招聘
    $('.zp-dt').click(function() {
      //$(this).addClass('active').siblings('.rczp-item').removeClass('active');
      $(this).parents('.zp-item').toggleClass('active');
      //$(this).siblings('.rczp-zt').slideToggle();
  })


$('.sp-tc').click(function(){
  console.log('2234')
  var $url=$(this).attr('data-url');
   $.getJSON('/plus/ajaxtengxun.php', {url: $url}, function(res) {
           /*optional stuff to do after success */
           if(res.code==200){
             console.log(res)
           layer.open({
              type: 1,
              content: '<video style="width:100%" autoplay src="'+res.result+'" controls="controls"></video>',
              maxmin: true
            });


           }
    })

})


$('.xh-tab-nav li').hover(function(event) {
  /* Act on the event */
  var xh_pr = $(this).parents('.xh-tab');
  var xh_sl = xh_pr.find('.xh-tab-content');
  var this_index = $(this).index();
  $(this).addClass('active').siblings().removeClass('active');
  xh_sl.find('.xh-tab-item').eq(this_index).addClass('active').siblings().removeClass('active');
});

$('.getAddress').click(function(){
  var address=$(this).attr('address')
  var url="http://api.map.baidu.com/geocoder?address="+address+"韩氏板材&output=html&src=webapp.baidu.openAPIdemo"
   //var url = "http://map.baidu.com/?l=&s=s%26wd%3D"+address+"韩氏板材&output=html";
   window.open(url,"_blank");
 })
 $('.a-4').find('.load-more').click(function(){
   $('.a-4-ul').css("height", "auto");
   $(this).hide()
 })

 $('.list-al li').click(function (event) {
  event.stopPropagation()
  let arr = $(this).attr('data-imgs').split(',');
  const host =$(this).attr('data-host')
  arr = arr.map(res=>{
     res=host+res
     return res
  })
  const tit=$(this).attr('data-tit'),x1=$(this).attr('data-x1'),x2=$(this).attr('data-x2')
  $('#x-tit').html(tit)
  $('#x1').html(x1)
  $('#x2').html(x2)
  var bannerHtml = ''
  arr.map(res => {
    bannerHtml += '<div class="swiper-slide"><img src="' + res + '"></div>';
  })
  $('.al-wrapper').html(bannerHtml)
  clickbj('al-tc')
})


function clickbj(htm) {
  var tcbj = $('.tc-bj')
  var tczt = $('.' + htm)
  var hide = function () {
      tczt.hide();
      tcbj.hide();
    },
    show = function () {
      tczt.show();
      tcbj.show();
    },
    close = function () {
      if (!tcbj.length > 0) { //判  断背景层是否存在
        $("<div class='tc-bj'></div>")
          .css({
            position: 'fixed',
            top: 0,
            left: 0,
            right: 0,
            bottom: 0,
            backgroundColor: "#000000",
            opacity: 0.7,
            zIndex: 500
          })
          .hide().appendTo("body");
        tcbj = $('.tc-bj');
      };
      tcbj.on('click', function () {
        hide();
      })
    };
  close()
  show()
}